package com.freecloud.spring.common;

import java.io.Serializable;

/**
 * @Author: maomao
 * @Date: 2021-05-17 13:32
 */
public class ResponseBody<T> implements Serializable {

    private static final String OK = "";
    private static final String ERROR = "error";
    private static final long serialVersionUID = -6030310387642185336L;

    private boolean success;
    private String message;
    private int code;
    private T data;

    public ResponseBody success() {
        this.success = true;
        this.message = OK;
        return this;
    }

    public ResponseBody failure() {
        this.success = false;
        this.message = ERROR;
        return this;
    }

    public ResponseBody failure(String message) {
        this.success = false;
        this.message = message;
        return this;
    }

    public ResponseBody data(T data) {
        this.data = data;
        return this;
    }

    public ResponseBody code(int code) {
        this.code = code;
        return this;
    }

    public ResponseBody message(String message) {
        this.message = message;
        return this;
    }

    public int getCode() {
        return code;
    }

    public boolean isSuccess() {
        return success;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }
}